package com.AntiThesis.atmodtx2;

import net.minecraft.client.Minecraft;
import net.minecraft.entity.Entity;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;

import java.util.HashMap;
import java.util.List;
import java.util.Random;

public class ShareEffect {
    static Random random = new Random();
    HashMap<String, String> map = new HashMap();

    public void skill(String[] s) {
        for (int i = 0; i < s.length; i++) {
            map.put("value" + i, s[i]);
        }
        castskill(map);

    }
    private void castskill(HashMap<String, String> map) {
        double x = Double.parseDouble(map.get("value0"));
        double y = Double.parseDouble(map.get("value1"));
        double z = Double.parseDouble(map.get("value2"));
        double area = Double.parseDouble(map.get("value3"));
        String particleType = (map.get("value4"));
        World world = Minecraft.getMinecraft().player.world;
        double x2 = Double.parseDouble(map.get("value5"));
        double y2 = Double.parseDouble(map.get("value6"));
        double z2 = Double.parseDouble(map.get("value7"));
        double xyzanglestart = Double.parseDouble(map.get("value8"));

        double speed = Double.parseDouble(map.get("value9"));
        double amount = Double.parseDouble(map.get("value10"));
        String castuid = map.get("value11");
        String xadd = map.get("value12");
        String yadd = map.get("value13");
        String zadd = map.get("value14");
        Entity player = null;

        List<Entity> loadedEntityList = Minecraft.getMinecraft().world.getLoadedEntityList();
        for (Entity entity : loadedEntityList) {
            if (entity.getUniqueID().toString().equals(castuid)){
                player=entity;
            }
        }

        Minecraft.getMinecraft().addScheduledTask(() -> {

            Vec3d add= new Vec3d(x,y,z);
            Vec3d add2= new Vec3d(x,y,z);
            if (!yadd.equals("0")||(!xadd.equals("0")||!zadd.equals("0"))){
                for(double n = 0.0D; n <= 3.141592653589793D; n += 0.3141592653589793D / amount) {
                    double sin = Math.sin(n) * area;
                    double cos = Math.cos(n) * area;

                    for(double n2 = 0.0D; n2 < 6.283185307179586D; n2 += 0.3141592653589793D / amount) {
                        double n3 = Math.cos(n2) * sin * area;
                        double n4 = Math.sin(n2) * sin * area;
                        add = add.add(new Vec3d(n3, cos*xyzanglestart, n4));

                        world.spawnParticle(EnumParticleTypes.valueOf(particleType),add.x,add.y,add.z,Double.parseDouble(xadd)*speed ,Double.parseDouble(yadd)*speed,Double.parseDouble(zadd)*speed);
                        add = add.subtract(n3, cos*xyzanglestart , n4);
                    }
                }
            }
            else {
                for(double n = 0.0D; n <= 3.141592653589793D; n += 0.3141592653589793D / amount) {
                    double sin = Math.sin(n) * area;
                    double cos = Math.cos(n) * area;

                    for(double n2 = 0.0D; n2 < 6.283185307179586D; n2 += 0.3141592653589793D / amount) {
                        double n3 = Math.cos(n2) * sin * area;
                        double n4 = Math.sin(n2) * sin * area;
                        add = add.add(new Vec3d(n3, cos*xyzanglestart, n4));
                        Vec3d subtract = add2.subtract(add).normalize();
                        world.spawnParticle(EnumParticleTypes.valueOf(particleType),add.x,add.y,add.z,subtract.x*speed ,subtract.y*speed*Double.parseDouble(yadd),subtract.z*speed);
                        add = add.subtract(n3, cos*xyzanglestart, n4);
                    }
                }
            }});

    }


}
